/**检验表单*/
function checkForm(form){
	var mesg = null;
	//索引，输入项
    $.each(form ,function(index ,obj) {
		//去前后空格
		var value = $.trim(obj.value);
		$(obj).val(value);
		var brothers = $(obj).siblings();
		var name = null;
		var need = false;
		$.each(brothers ,function(index2 ,brother) {
			var nodeName = brother.nodeName;
			var className = brother.className;
			if(nodeName == "SPAN" && className == "need_red"){
				need = true;
			}else if(nodeName == "LABEL"){
				name = brother.innerText;
			}
			//两者都需要作为输入的兄弟节点，否则不生效
			if(need && name != null){
			    if(obj.type == "checkbox" && obj.checked == false){
			        //红色星号之前就是标题
                    mesg = name + "没有勾选";
                    //跳出整个循环
                    return false;
			    }else if(value == ""){
					//红色星号之前就是标题
					mesg = name + "的值为空";
					//跳出整个循环
					return false;
				}
			}
		});
		if(mesg != null){
			//跳出整个循环
			return false;
		}
	});
	return mesg;
}

/**日期格式化*/
function dataFomart(date, fomart){
    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    if(m < 10){
        m = "0" + m;
    }
    let d = date.getDate();
    if(d < 10){
        d = "0" + d;
    }
    if(fomart == 'yyyy-mm-dd'){
        return `${y}-${m}-${d}`;
    }else{
        return `${y}-${m}-${d}`;
    }
}

/**数组根据数组对象中的某个属性值进行排序的方法
* 使用例子：newArray.sort(sortByArr("date:desc,timing:asc"))
* @param keysSort 排序的属性 "date:desc,timing:asc"
*/
function sortByKeys(keysSort) {
    return function(a, b) {
        let keysSortArray = keysSort.split(",");
        for(var index in keysSortArray){
            let sorts = keysSortArray[index].split(":");
            let key = sorts[0];
            let sort = sorts[1];
            if (a[key] != b[key]) {
                //降序
                rev = -1;
                if(sort == "asc"){
                    rev = 1;
                }
                if (a[key] > b[key]) {
                    return rev * 1;
                } else {
                    return rev * -1;
                }
            }
        }
    }
}
/**从某个序列里获得下一个递增的排序号，要求长度一致*/
function orderNum(array,key,index){
    //拿到对应的数组
    var a = new Array();
    for(var i = 0; i < array.length; i++){
        let order = array[i][key];
        if(!(order == null || order == "")){
            a.push(order);
        }
    }
    a.sort();
    var order = a[a.length - 1];
    var num = order.substring(index, order.length);
    num = parseInt(num) + 1;
    num = ("" + num).padStart(4, "0");
    order = order.substring(0, index);
    return order + num;
}

/*
function isAnd(params){
	if(params.indexOf("&") >= 0){
		return true;
	}else{
		return false;
	}
}

function getParams(params){
	var index = params.indexOf("?") + 1;
	params = params.substring(index ,params.length);
	if(params.indexOf("&") >= 0){
		params = params.split("&");//参数KV
	}else{
		params = params.split("|");//参数KV
	}
	return params;
}

function getData(result, params){
	var data = new Array();
	var index = 0;
	if(isAnd(params)){
		params = params.split("&");//参数KV
		for(var i = 0; i < result.length; i++){
			var isIt = true;	
			for(var j = 0; j < params.length; j++){
				var param = params[j].split("=");
				if(result[i][param[0]] != param[1]){
					isIt = false;
					break;
				}
			}
			if(isIt){
				data[index] = result[i];
				index++;
			}
		}
	}else{
		params = params.split("|");//参数KV
		for(var i = 0; i < result.length; i++){
			var isIt = true;	
			for(var j = 0; j < params.length; j++){
				var param = params[j].split("=");
				if(result[i][param[0]] == param[1]){
					data[index] = result[i];
					index++;
					break;
				}
			}
		}
	}
	return data;
}

function getSingleData(result, col, params){
	params = getParams(params);
	for(var i = 0; i < result.length; i++){
		var isIt = true;	
		for(var j = 0; j < params.length; j++){
			var param = params[j].split("=");
			if(result[i][param[0]] != param[1]){
				isIt = false;
				break;
			}
		}
		if(isIt){
			return result[i][col];
		}
	}
}

function delData(result, params){
	params = getParams(params);
	for(var i = 0; i < result.length; i++){
		var isIt = true;	
		for(var j = 0; j < params.length; j++){
			var param = params[j].split("=");
			if(result[i][param[0]] == param[1]){
				delete result[i];
			}
		}
	}
}

function update(result, params, newVals){
	params = getParams(params);
	newVals = getParams(newVals);
	for(var i = 0; i < result.length; i++){
		var isIt = true;	
		for(var j = 0; j < params.length; j++){
			var param = params[j].split("=");
			if(result[i][param[0]] != param[1]){
				isIt = false;
				break;
			}
		}
		if(isIt){
			for(var j = 0; j < newVals.length; j++){
				var newVal = newVals[j].split("=");
				result[i][newVal[0]] = newVal[1];
			}
		}
	}
}
*/